package cap.action;

import cap.bean.ChatRoomVo;
import cap.dao.ChatRoomDao;
import cap.dao.impl.ChatRoomDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/createroom")
public class createroomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf8");
        ChatRoomDao chatroomDao = new ChatRoomDaoImpl();
        ChatRoomVo chartroomVo = new ChatRoomVo();
        String state = "failed";
        chartroomVo.setContent(request.getParameter("content"));
        chartroomVo.setRoomhost(request.getParameter("roomhost"));
        chartroomVo.setRoomname(request.getParameter("roomname"));
        chartroomVo.setRoomnumber(Integer.parseInt(request.getParameter("roomnumber")));
        try {
            chatroomDao.setChartroomVo(chartroomVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect("front/chatRoom.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
